const express = require('express');
// 创建一个应用程序 实例
const app = express();

// 中间件其实就是一个特殊的函数 
const middleware1 = (req, res, next) => {
  req.a = 10;
  console.log('1');
  next();
  console.log('1-1');
}
const middleware2 = (req, res, next) => {
  console.log('2');
  next();
  console.log('2-2');
}
const middleware3 = (req, res, next) => {
  console.log('3');
  next();
  console.log('3-3');
}
// 使用中间件 app.use()
// app.use('/home', middleware1)
app.use(middleware1);
app.use(middleware2);
app.use(middleware3);
app.get("/home", (req, res) => {
  console.log(req.a);
  res.send("你好我是首页222")
})
app.get("/a", (req, res) => {
  res.send("a路由")
})

// 分配端口 并启动服务
app.listen(
  9527,
  () => {
    console.log('start at port 9527');
  }
)